<html>
    <head>
        <title>修复测试</title>
    </head>
    <body>
        <script>
            /*
                 5、修复测试  Fixing the Tests 
                                   
                                            创建新的DbContext会破坏集成测试。很容易修复。

                                            在BookStore.EntityFrameworkCore.Tests项目中打开BookStoreEntityFrameworkCoreTestModule类，找到CreateDatabaseAndGetConnection方法。
                                            
                                            应该是这样的：
                                                                        
                                                    private static SqliteConnection CreateDatabaseAndGetConnection()
                                                    {
                                                        var connection = new SqliteConnection("Data Source=:memory:");
                                                        connection.Open();

                                                        var options = new DbContextOptionsBuilder<BookStoreDbContext>()
                                                            .UseSqlite(connection)
                                                            .Options;

                                                        using (var context = new BookStoreDbContext(options))
                                                        {
                                                            context.GetService<IRelationalDatabaseCreator>().CreateTables();
                                                        }

                                                        return connection;
                                                    }
                                            
                                            将其更改为以下内容：

                                                    private static SqliteConnection CreateDatabaseAndGetConnection()
                                                    {
                                                        var connection = new SqliteConnection("Data Source=:memory:");
                                                        connection.Open();

                                                        var options = new DbContextOptionsBuilder<BookStoreDbContext>()
                                                            .UseSqlite(connection)
                                                            .Options;

                                                        using (var context = new BookStoreDbContext(options))
                                                        {
                                                            context.GetService<IRelationalDatabaseCreator>().CreateTables();
                                                        }

                                                        // Add the following code --------------
                                                        var optionsForSecondDb = new DbContextOptionsBuilder<BookStoreSecondDbContext>()
                                                            .UseSqlite(connection)
                                                            .Options;

                                                        using (var context = new BookStoreSecondDbContext(optionsForSecondDb))
                                                        {
                                                            context.GetService<IRelationalDatabaseCreator>().CreateTables();
                                                        }
                                                        //--------------------------------------

                                                        return connection;
                                                    }    
                                                        
                                        集成测试现在可以工作了。我在测试中使用了相同的数据库以保持简单。
            */
        </script>
    </body>
</html>